package xyz.yuzegod.megawalls.classes.novice.zombie;

import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class ThirdSkill extends Skill
{
    public ThirdSkill(final Classes classes) {
        super("飓风", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 0.08;
            }
            case 2: {
                return 0.16;
            }
            case 3: {
                return 0.24;
            }
            default: {
                return 0.08;
            }
        }
    }
    
    public int getSeconds(final int level) {
        switch (level) {
            case 1: {
                return 3;
            }
            case 2: {
                return 4;
            }
            case 3: {
                return 5;
            }
            default: {
                return 3;
            }
        }
    }
    
    public int getCooldownSeconds(final int level) {
        switch (level) {
            case 1: {
                return 32;
            }
            case 2: {
                return 25;
            }
            case 3: {
                return 18;
            }
            default: {
                return 32;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7被箭矢命中时,获得§a" + StringUtils.percent(this.getAttribute(level)) + "§7近战伤害加成");
            lore.add("   §7以及速度II效果,持续§a" + this.getSeconds(level) + "§7秒。");
            lore.add(" ");
            lore.add("§7冷却时间：§a32秒");
            return lore;
        }
        lore.add(" §8▪ §7被箭矢命中时,获得§8" + StringUtils.percent(this.getAttribute(level - 1)) + " ➜");
        lore.add("   §a" + StringUtils.percent(this.getAttribute(level)) + "§7近战伤害加成");
        lore.add("   §7以及速度II效果,持续§8" + this.getSeconds(level - 1) + " ➜ §a" + this.getSeconds(level) + "§7秒。");
        lore.add("§7冷却时间：§8" + this.getCooldownSeconds(level - 1) + "秒 ➜ §a" + this.getCooldownSeconds(level) + "秒");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill3Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill3Level();
    }
    
    @Override
    public boolean use(final GamePlayer gamePlayer, final KitStatsContainer kitStats) {
        if (Zombie.skill3Cooldown.getOrDefault(gamePlayer, 0) > 0) {
            return false;
        }
        final Player player = gamePlayer.getPlayer();
        final int level = kitStats.getSkill3Level();
        if (player.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE)) {
            player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
        }
        player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, this.getSeconds(level) * 20, 0));
        if (player.hasPotionEffect(PotionEffectType.SPEED)) {
            player.removePotionEffect(PotionEffectType.SPEED);
        }
        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, this.getSeconds(level) * 20, 1));
        Zombie.skill3Cooldown.put(gamePlayer, this.getCooldownSeconds(level));
        return true;
    }
    
    @Override
    public String getSkillTip(final GamePlayer gamePlayer) {
        return this.getClasses().getNameColor() + "§l" + this.getName() + " " + ((Zombie.skill3Cooldown.getOrDefault(gamePlayer, 0) == 0) ? "§a§l✓" : ("§c§l" + Zombie.skill3Cooldown.get(gamePlayer) + "秒"));
    }
}
